//
//  MeViewController.m
//  Socrates
//
//  Created by shy on 15/3/8.
//  Copyright (c) 2015年 shy. All rights reserved.
//

#import "SettingsViewController.h"

#import "MeCell.h"
#import "AboutUsViewController.h"
#import "SuggestionBackViewController.h"
#import "ResetCodeViewController.h"
#import "RDVTabBarController.h"

typedef enum {
    kMe_about_us_item = 0,
    kMe_upgrade_version_item,
    kMe_share_friends_item,
    kMe_suggestion_back_item,
    kMe_reset_code_item,
    kMe_clear_cache_item,
    kLimitation_Num,
} MeItems;

static const int kLimitationRowHeight = 40;

@interface SettingsViewController () {
    
}

@end

@implementation SettingsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor colorWithRed:239/255. green:239/255. blue:244/255. alpha:1.];
    [self.tableView registerNib:[UINib nibWithNibName:@"MeCell" bundle:nil] forCellReuseIdentifier:@"MeCellIdentifier"];
    self.tableView.separatorInset = UIEdgeInsetsMake(0, 23, 0, 15);
    self.navigationItem.title = @"设置";
    self.tableView.scrollEnabled = NO;
    [self configLogout];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)configLogout {
    [self.logout setBackgroundColor:[UIColor colorWithRed:252/255. green:108/255. blue:108/255. alpha:1.]];
    [self.logout setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self.logout setTitle:@"退出登录" forState:UIControlStateNormal];
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 20;
}

- (UIView*)tableView:(UITableView*)tableView viewForHeaderInSection:(NSInteger)section {
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 20)];
    view.backgroundColor = [UIColor colorWithRed:239/255. green:239/255. blue:244/255. alpha:1.];
    return view;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return kLimitationRowHeight;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return kLimitation_Num;
}

- (MeCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSString *cellIdentifier = @"MeCellIdentifier";
    MeCell *cell = [self.tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (!cell) {
        cell = [[MeCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }
    
    switch ([indexPath row]) {
        case kMe_about_us_item:
            cell.settingsImage.image = [UIImage imageNamed:@"about_us"];
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
            cell.settingsType.text = @"关于我们";
            break;
        case kMe_upgrade_version_item:
            cell.settingsImage.image = [UIImage imageNamed:@"upgrade_version"];
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
            cell.settingsType.text = @"版本更新";
            break;
        case kMe_share_friends_item:
            cell.settingsImage.image = [UIImage imageNamed:@"share_friends"];
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
            cell.settingsType.text = @"分享给朋友";
            break;
        case kMe_suggestion_back_item:
            cell.settingsImage.image = [UIImage imageNamed:@"suggestion_back"];
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
            cell.settingsType.text = @"反馈建议";
            break;
        case kMe_reset_code_item:
            cell.settingsImage.image = [UIImage imageNamed:@"reset_code"];
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
            cell.settingsType.text = @"修改密码";
            break;
        case kMe_clear_cache_item:
            cell.settingsImage.image = [UIImage imageNamed:@"clear_cache"];
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
            cell.settingsType.text = @"清除缓存";
            break;
        default:
            break;
    }
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
    switch ([indexPath row]) {
        case kMe_about_us_item:
            [self launchAboutUsViewController];
            break;
        case kMe_upgrade_version_item:
            break;
        case kMe_share_friends_item:
            break;
        case kMe_suggestion_back_item:
            [self launchSuggestionBackViewController];
            break;
        case kMe_reset_code_item:
            [self launchResetCodeViewController];
            break;
        case kMe_clear_cache_item:
            break;
        default:
            break;
    }
}

- (void)launchAboutUsViewController {
    AboutUsViewController *vc = [[AboutUsViewController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)launchSuggestionBackViewController {
    SuggestionBackViewController *vc = [[SuggestionBackViewController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)launchResetCodeViewController {
    ResetCodeViewController *vc = [[ResetCodeViewController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    [[self rdv_tabBarController] setTabBarHidden:YES animated:YES];
}

- (void)viewWillDisappear:(BOOL)animated {
    [[self rdv_tabBarController] setTabBarHidden:NO animated:YES];
    
    [super viewWillDisappear:animated];
}

@end
